Public Class frmDClientes
    Dim MiGestDatos As New GestDatos()
    Dim _CodCliente As String
    Dim _NPedido As Integer
    Dim _NSerie As String
    Dim _FechaPed As Date
    Dim MiCursorRaton As New GestProyecto

    Private Sub Conectar(ByVal CodCliente As String)

        Dim Ruta As String
        Ruta = "Data Source =" & System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) & "\DBGestion.sdf;"
        Dim LineaSQL(1) As String
        Dim Tabla(1) As String
        LineaSQL(0) = "Select * From Clientes WHERE CodCliente ='" & txtCod.Text & "'"
        Tabla(0) = "Clientes"
        LineaSQL(1) = "Select Pedidos,FechaPed,Importe,NCliente,NSerie From Pedidos WHERE NCliente ='" & txtCod.Text & "'"
        Tabla(1) = "Pedidos"
        MiGestDatos = New GestDatos
        MiGestDatos.ConextarBD(Ruta, LineaSQL, Tabla)

        MostrarDatos()

    End Sub

    Private Sub frmDClientes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MiCursorRaton.CursorRaton(True)

        Dim MiCodCliente As String = txtCod.Text
        Conectar(MiCodCliente)

        MiCursorRaton.CursorRaton(False)

    End Sub


    Friend ReadOnly Property NCliente() As String
        Get
            Return _CodCliente
        End Get
    End Property

    Friend ReadOnly Property NPedido() As Integer
        Get
            Return _NPedido
        End Get
    End Property
    Friend ReadOnly Property NSerie() As String
        Get
            Return _NSerie
        End Get
    End Property
    Friend ReadOnly Property FechaPed() As Date
        Get
            Return _FechaPed
        End Get
    End Property

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

        Me.Dispose()

    End Sub

    Private Sub MostrarDatos()

        With MiGestDatos.DataSet.Tables("Clientes")
            If Not .Rows(0)("Cliente") Is System.DBNull.Value Then
                txtCliente.Text = .Rows(0)("Cliente")
            Else
                txtCliente.Text = ""
            End If
            If Not .Rows(0)("Direccion") Is System.DBNull.Value Then
                txtDireccion.Text = .Rows(0)("Direccion")
            Else
                txtDireccion.Text = ""
            End If
            If Not .Rows(0)("Localidad") Is System.DBNull.Value Then
                txtPoblacion.Text() = .Rows(0)("Localidad")
            Else
                txtPoblacion.Text = ""
            End If
            If Not .Rows(0)("CP") Is System.DBNull.Value Then
                txtCP.Text() = .Rows(0)("CP")
            Else
                txtCP.Text = ""
            End If
            If Not .Rows(0)("Provincia") Is System.DBNull.Value Then
                txtProvincia.Text = .Rows(0)("Provincia")
            Else
                txtProvincia.Text = ""
            End If
            If Not .Rows(0)("Telefono1") Is System.DBNull.Value Then
                txtTelefono1.Text = .Rows(0)("Telefono1")
            Else
                txtTelefono1.Text = ""
            End If
            If Not .Rows(0)("Telefono2") Is System.DBNull.Value Then
                txtTelefono2.Text = .Rows(0)("Telefono2")
            Else
                txtTelefono2.Text = ""
            End If
            If Not .Rows(0)("Fax") Is System.DBNull.Value Then
                txtFax.Text = .Rows(0)("Fax")
            Else
                txtFax.Text = ""
            End If
            If Not .Rows(0)("Email") Is System.DBNull.Value Then
                txtEmail.Text = .Rows(0)("Email")
            Else
                txtEmail.Text = ""
            End If
            If Not .Rows(0)("Notas") Is System.DBNull.Value Then
                txtNotas.Text = .Rows(0)("Notas")
            Else
                txtNotas.Text = ""
            End If
            If Not .Rows(0)("DniCif") Is System.DBNull.Value Then
                txtDniCif.Text = .Rows(0)("DniCif")
            Else
                txtDniCif.Text = ""
            End If

        End With

    End Sub
    Private Sub TabDCLientes_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabDCliente.SelectedIndexChanged

        MiCursorRaton.CursorRaton(True)

        If tabDCliente.SelectedIndex = 2 Then
            Pedidos()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub Pedidos()

        Dim grdEmcabezados As New GestDatos.Emcabezados

        grdEmcabezados.add(New GestDatos.Emcabezado("FechaPed", "FECHA", 60))
        grdEmcabezados.add(New GestDatos.Emcabezado("NSerie", "S", 20))
        grdEmcabezados.add(New GestDatos.Emcabezado("Pedidos", "PEDIDO", 67))
        grdEmcabezados.add(New GestDatos.Emcabezado("Importe", "TOTAL", 67))

        MiGestDatos.DatosGrid(grdPedidos, grdEmcabezados, "Pedidos", "")

    End Sub

    Private Sub grdPedidos_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPedidos.Click

        MiCursorRaton.CursorRaton(True)

        grdPedidos.Select(grdPedidos.CurrentRowIndex)

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub grdPedidos_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPedidos.DoubleClick

        MiCursorRaton.CursorRaton(True)

        _CodCliente = txtCod.Text
        _NSerie = grdPedidos.Item(grdPedidos.CurrentRowIndex, 1).ToString
        _NPedido = grdPedidos.Item(grdPedidos.CurrentRowIndex, 2).ToString
        _FechaPed = grdPedidos.Item(grdPedidos.CurrentRowIndex, 0).ToString
        frmInicio.Nuevo = False
        frmInicio.MifrmPedido = New frmPedido
        frmInicio.MifrmPedido.Show()

        MiCursorRaton.CursorRaton(False)
        
    End Sub
End Class
